<?php
/**
 * Created by PhpStorm.
 * User: evenvi
 * Date: 16-7-14
 * Time: 下午4:49
 * Contact: ${Contact}
 */
class Make extends CI_Controller
{
    private $_qiniu_access_key;
    private $_qiniu_secret_key;
    private $_qiniu_hub;

    private $credentials;
    private $hub;

    function __construct()
    {
        $qiniu_config = $this->config->item('qiniu_config');
        $this->_qiniu_access_key = $qiniu_config['access_key'];
        $this->_qiniu_secret_key = $qiniu_config['secret_key'];
        $this->_qiniu_hub = $qiniu_config['hub'];

        $this->credentials = new \Qiniu\Credentials($this->_qiniu_access_key, $this->_qiniu_secret_key);
        $this->hub = new \Pili\Hub($this->credentials, $this->_qiniu_hub);
    }

    function new_stream()
    {
        try
        {
            $title = NULL;
            $publishKey = NULL;
            $publishSecurity = NULL;

            $stream = $this->hub->createStream($title, $publishKey, $publishSecurity);

            echo "createStream() =>\n";
            var_export($stream);
            echo "\n\n";
        }
        catch (Exception $e)
        {
            echo 'createStream() failed. Caught exception: ',  $e->getMessage(), "\n";
        }
    }
}